package com.compass.mobile.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.FragmentTransaction
import com.compass.mobile.R
import com.compass.mobile.databinding.ActivityHomePageBinding
import com.compass.mobile.framework.base.BaseVBActivity
import com.compass.mobile.framework.constant.KEY_TYPE
import com.compass.mobile.framework.constant.PATIENT_SWITCH
import com.compass.mobile.framework.ifly.IFlyHelper
import com.compass.mobile.framework.utils.LiveDataBus
import com.compass.mobile.ui.fragment.DepartmentFragment
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
 * Description：科室列表
 * Date:2024/6/3 22:19
 */
class DepartmentFragmentActivity : BaseVBActivity<ActivityHomePageBinding>() {

    companion object {
        fun start(context: Context,comeType:String) {
            val intent = Intent(context, DepartmentFragmentActivity::class.java)
            intent.putExtra(KEY_TYPE, comeType)
            context.startActivity(intent)
        }
    }
    private var comeType: String? = null
    private lateinit var  departmentFragment:DepartmentFragment
    override fun initView(savedInstanceState: Bundle?) {
        comeType = intent.getStringExtra(KEY_TYPE)

        departmentFragment = DepartmentFragment()
        val bundle = Bundle()
        bundle.putString(KEY_TYPE, comeType)
        departmentFragment.arguments = bundle

        val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
        fragmentTransaction.replace(R.id.fragmentContainer, departmentFragment)
        fragmentTransaction.commit()
        //初始化注释掉
//        GlobalScope.launch(Dispatchers.Main) {
//            delay(1000)
//            IFlyHelper.initIFly(this@DepartmentFragmentActivity,null)
//        }

        // 切换就诊人需要刷新
        LiveDataBus.get().with(PATIENT_SWITCH, String::class.java) .observe(this) {
            mBinding.topView.setDefaultPatientInfo()
        }

    }

    override fun onDestroy() {
        super.onDestroy()
//        GlobalScope.launch(Dispatchers.Main) {
//            delay(1000)
//            IFlyHelper.cancelText()
//        }

    }
}
